﻿using Demo.ProductService.Services;
using Demo.ProductService.Services.Dtos;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;

namespace Shop.PcWebSite.Controllers
{
    /// <summary>
    /// 应用层控制器
    /// </summary>
    [ApiController]
    [Route("index")]
    public class IndexController : AbpController
    {
        /// <summary>
        /// 此处IProductService服务中的命名空间需要保持与微服务Shop.ProductService一致
        /// </summary>
        public IProductService productService { get; set; }


        /// <summary>
        /// 添加商品方法
        /// </summary>
        /// <returns></returns>
        [HttpPost("AddProduct")]
        public async Task<ProductDto> AddProduct(ProductDto productDto)
        {
            // 1、实现添加商品
            Console.WriteLine("实现添加商品");
            try
            {
                var result = await productService.CreateAsync(productDto);

                return result;
            }
            catch (Exception e)
            {

                throw;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<ProductDto>> GetProductsAsync()
        {
            //1、查询商品
            Console.WriteLine("查询商品");
            try
            {

                var result = await productService.GetProductsAsync();

                return result;
            }
            catch (Exception e)
            {

                throw;
            }
        }


    }
}
